// Framework: None
// Technology stack: None

#include <iostream>
#include <string>
#include <unordered_map>

bool is_prime(int num) {
    if (num < 2) {
        return false;
    }
    for (int i = 2; i <= sqrt(num); i++) {
        if (num % i == 0) {
            return false;
        }
    }
    return true;
}

void x(std::string s) {
    std::unordered_map<std::string, int> numbers = {
        {"zero", 0}, {"one", 1}, {"two", 2}, {"three", 3}, {"four", 4},
        {"five", 5}, {"six", 6}, {"seven", 7}, {"eight", 8}, {"nine", 9}
    };

    if (s.length() != 3) {
        std::cout << "Wrong input" << std::endl;
        return;
    }

    std::string number = "";
    std::string word;
    for (char c : s) {
        if (c == ' ') {
            if (numbers.find(word) != numbers.end()) {
                number += std::to_string(numbers[word]);
            }
            else {
                std::cout << "Wrong input" << std::endl;
                return;
            }
            word = "";
        }
        else {
            word += c;
        }
    }
    if (numbers.find(word) != numbers.end()) {
        number += std::to_string(numbers[word]);
    }
    else {
        std::cout << "Wrong input" << std::endl;
        return;
    }

    int num = std::stoi(number);

    if (num >= 100 && num <= 999 && is_prime(num)) {
        std::cout << num << std::endl;
        return;
    }

    int lower = num - 1;
    int upper = num + 1;
    while (true) {
        if (lower >= 100 && is_prime(lower)) {
            std::cout << lower << std::endl;
            return;
        }
        else if (upper <= 999 && is_prime(upper)) {
            std::cout << upper << std::endl;
            return;
        }
        lower--;
        upper++;
    }

    std::cout << "Wrong input" << std::endl;
}

int main() {
    std::string input_str;
    std::cout << "Enter three words: ";
    std::getline(std::cin, input_str);
    x(input_str);

    return 0;
}